package com.saltedfish.tool.ui.flag.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.saltedfish.tool.R;
import com.saltedfish.tool.util.UIUtils;

import java.util.List;

import cn.droidlover.xdroidmvp.base.SimpleListener;
import cn.droidlover.xdroidmvp.log.XLog;


public class SelectFlagColorAdapter extends BaseQuickAdapter<Integer, BaseViewHolder> {

    private SimpleListener listener;

    private Context mContext;

    private int selectPosition = 0;

    private int screenWidth = 0;


    public void setListener(SimpleListener listener) {
        this.listener = listener;
    }

    public SelectFlagColorAdapter(List<Integer> data, Context context) {
        super(R.layout.layout_select_color, data);
        this.mContext = context;
        this.screenWidth = UIUtils.getScreenWidth(context);
    }

    public void setSelectPosition(int position){
        this.selectPosition = position;
        notifyDataSetChanged();
    }


    @Override
    protected void convert(BaseViewHolder helper, Integer resoure) {
        View mColor = helper.getView(R.id.view_color);
        RelativeLayout re_selectColor = helper.getView(R.id.re_selectColor);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        layoutParams.width = UIUtils.getScreenWidth(mContext)/6;
        layoutParams.height = UIUtils.getScreenWidth(mContext)/6;
        re_selectColor.setLayoutParams(layoutParams);
        if(resoure !=null){
            mColor.setBackgroundResource(resoure);
        }

        int position = helper.getAdapterPosition();

        if(position == selectPosition){
            if(position == 0){
                mColor.setBackgroundResource(R.drawable.shape_radius_round_ff68_half);

            }else if(position == 1){
                mColor.setBackgroundResource(R.drawable.shape_radius_round_ff9b_half);

            }else if(position == 2){
                mColor.setBackgroundResource(R.drawable.shape_radius_round_ffc7_half);

            }else if(position == 3){
                mColor.setBackgroundResource(R.drawable.shape_radius_round_a3e9_half);

            }else if(position == 4){
                mColor.setBackgroundResource(R.drawable.shape_radius_round_3097_half);

            }else if(position == 5){
                mColor.setBackgroundResource(R.drawable.shape_radius_round_ca7a_half);

            }
        }

        mColor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(listener !=null){
                    listener.onClick(position);
                    setSelectPosition(position);

                }
            }
        });


    }


}
